package com.falidos.visao.servlets;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet Filter implementation class ValidaLogon
 */
@WebFilter("/ValidaLogon")
public class ValidaLogon extends SuperServlet implements Filter {
	private static final long serialVersionUID = 1L;


	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpSession session = ((HttpServletRequest) request).getSession();
		HttpServletResponse resp = (HttpServletResponse) response;
		String logged = (String) session.getAttribute("logged");
		if(session == null || logged == null || !logged.equals("true")){
			resp.sendRedirect("/falidos.com/erro/erroAuth.jsp");
		}else{
			chain.doFilter(request, response);
		}
	}

	
	public void init(FilterConfig fConfig) throws ServletException {
		
	}

}
